// 通过正则表达式验证表单的格式是否正确
window.addEventListener('load', function () {
    var tele = document.querySelector('.tele');
    var verify = document.querySelector('.verify');
    var pwd = document.querySelector('.pwd');
    var verifyPwd = document.querySelector('.verify-pwd');
    var waitVerify = [tele, verify, pwd];
    var test1 = [/^[0-9]{11}$/, /^[0-9]{6}$/, /^[a-zA-Z0-9_-]{6,16}$/];//电话号码验证
    function testSuccess() {
        this.nextElementSibling.innerHTML = '格式正确';
        this.nextElementSibling.className = 'success show';
    }
    function testError() {
        this.nextElementSibling.innerHTML = '格式不正确，请重新输入';
        this.nextElementSibling.className = 'error show';
    }
    for (var i = 0; i < waitVerify.length; i++) {
        (function (i) {
            waitVerify[i].addEventListener('blur', function () {
                var val = this.value;
                if (test1[i].test(val)) {
                    testSuccess.call(this);
                } else {
                    testError.call(this);
                }
            })
        })(i);
    }
    verifyPwd.addEventListener('blur', function () {
        var val = this.value;
        if (this.value && this.value === pwd.value) {
            testSuccess.call(this);
        } else if (this.value !== pwd.value) {
            testError.call(this);
        }
    })
})